<?php
namespace Admin\Controller;
class UserController extends AdminBaseController
{
   public function index()
    {
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $this->display('user/index');
        
    }
    
    public function ulist(){
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $mobile=I('mobile','');
        $email=I('email','');
        $cond='';
        if($mobile!='' and $email!=''){
            $cond=" and a.mobile=".$mobile." and a.email='".$email."'";
            $whe['mobile']=$mobile;
            $whe['email']=$email;
        }
        else if($mobile!='' and $email==''){
            $whe['mobile']=$mobile;
            $cond=' and a.mobile='.$mobile;
        } else if($mobile=='' and $email!='') {
            $whe['email']=$email;
            $cond=" and a.email='".$email."'";
        }
        $page=I('page',1);
        $rows=I('rows',50);
        $start=($page-1)*$rows;
        
        $sql="SELECT a.id,a.mobile,a.logindate,a.createdate,a.email,a.signumber,b.avail_money,b.present_money,b.locked_money,b.notpresent_money FROM dd_user a LEFT JOIN dd_user_assets b ON a.id=b.uid WHERE 1=1 ".$cond.' ORDER BY  a.createdate LIMIT '.$start.','.$rows;
        $dao = M();
        $list = $dao->query($sql);
        $count = M('User')->where($whe)->count();
        $map=array(
            'rows'=>$list,
            'total'=>$count
        );
        $this->ajaxReturn($map,'JSON');
    }  

 public function userpay(){ 
  if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $this->display("user/userpay");
    }  

    public function userpaylist(){

      if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $page=I('page',1);
        $rows=I('rows',50);
        $start=($page-1)*$rows;
        $sql="SELECT a.id,a.mobile,a.logindate,a.createdate,a.email,a.signumber,b.avail_money,b.present_money,b.locked_money,b.notpresent_money FROM dd_user a LEFT JOIN dd_user_assets b ON a.id=b.uid WHERE 1=1 ".$cond.' ORDER BY  a.createdate LIMIT '.$start.','.$rows;
        $dao = M();
        $list = $dao->query($sql);   
        $count = M('User')->where($whe)->count();
        $map=array(
            'rows'=>$list,
            'total'=>$count
        );
        $this->ajaxReturn($map,'JSON');
        exit();
    }
 public function usermoney(){   

      if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
       $id=I('id','');
       if($id==''){
        $map=array('status'=>2);
          $this->ajaxReturn($map,'JSON');
         exit();
       }
       $numbermoney=I('numbermoney',0);

       if($numbermoney!=0){
            M('UserAssets')->where('id='.$id)->setInc('avail_money',$numbermoney);
            M('UserAssets')->where('id='.$id)->setInc('notpresent_money',$numbermoney);
            $map=array('status'=>1);



            $paylog = M("AssetsLog"); // 实例化User对象
            $paylog->admin =session('auid');
            $paylog->uid = $id;
            $paylog->amount=$numbermoney;
            $paylog->createdate=date('y-m-d H:m:s',time());
            $paylog->add();

            $this->ajaxReturn($map,'JSON');
        exit();
       }else{
            $map=array('status'=>2);
            $this->ajaxReturn($map,'JSON');
            exit();
       }
      
  }  

  public function record(){
      $this->display('user/record');
  }
  
public function userpayrecordlist(){

       if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
       $page=I('page',1);
       $rows=I('rows',50);
       $start=($page-1)*$rows;
       $sql='SELECT a.id,b.mobile,c.account,a.amount,a.createdate FROM  dd_assets_log a LEFT JOIN dd_user  b ON a.uid=b.id left join dd_admin c on a.admin=c.id  ORDER BY  a.createdate LIMIT '.$start.','.$rows;
      
       $dao = M();
       $list = $dao->query($sql);   
       $count = M('AssetsLog')->count();
       $map=array(
           'rows'=>$list,
           'total'=>$count
       );
       $this->ajaxReturn($map,'JSON');
       exit();
   }
        

}